﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>修改学生信息</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script src="../Scripts/jquery-3.3.1.js"></script>
    <script src="../layui/layui.js" charset="utf-8"></script>
</head>
<body>
    
    <div class="layui-card">
        <div class="layui-card-header">修改密码</div>
        <div class="layui-card-body" pad15="">
          
          <div class="layui-form" lay-filter="">
            
            <div class="layui-form-item">
                
                  <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-inline">
                      <input type="password" name="password" autocomplete="off" placeholder="请输入密码" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">确认密码</label>
                    <div class="layui-input-inline">
                      <input type="password" name="passwordOnce"  autocomplete="off" placeholder="请输入确认密码"  class="layui-input">
                    </div>
                  </div>
            </div>
              <div class="layui-form-item">
              <div class="layui-input-block">
                <button type="button" class="layui-btn" id="submitBtn" onclick="return false;" >确认修改</button>
              </div>
            </div>
          </div>
          
        </div>
      </div>
    <script>
        layui.use(['form', 'layedit', 'layer', 'jquery'], function ()
        {
            var form = layui.form,
                layedit = layui.layedit,
                layer = layui.layer,
                $ = layui.jquery;


            $("input[name='password']").change(function ()
            {
                var len = $(this).val().length;
                if (len<6)
                {
                    layer.alert("账号长度过短", { icon: 4 });
                }
                var r = /^(([a-zA-Z]+[0-9]+)|([0-9]+[a-zA-Z]+)|([a-z]+[@#%])|([0-9]+[@#%]))([a-zA-Z0-9@#%]*)$/ ;
                if (!r.test($(this).val()))
                {
                    layer.alert("至少包含两种字符", { icon: 4 });
                    return;
                }
            });
            //对文本框约束
            $("input[name='password']").change(function ()
            {
                if ($(this).val() == "")
                {
                    layer.alert('密码框不能为空', { icon: 2, offset: '200px' });
                }
                var r = /^[a-zA-Z]\w{5,19}$/;
                if (!r.test($(this).val()))
                {
                    layer.tips("密码过于简单或者长度不对", "#password", { icon: 2 });
                    return;
                }
            })
            $("input[name='passwordOnce']").change(function ()
            {
                if ($(this).val() == "")
                {
                    layer.alert('密码框不能为空', { icon: 2, offset: '200px' });
                    return;
                }
                var r = /^[a-zA-Z]\w{5,19}$/;
                if (!r.test($(this).val()))
                {
                    layer.tips("密码过于简单或者长度不对", "#password", { icon: 2 });
                    return;
                }
            })
            $("#submitBtn").click(function ()
            {
                var p1 = $("input[name='password']").val().toString().trim();
                var p2 = $("input[name='passwordOnce']").val().toString().trim();
                if (p1 != p2)
                {
                    layer.alert('两次密码不一样', { icon: 2, offset: '200px' });
                    return;
                }
                if (p1 == "")
                {
                    layer.alert('密码框不能为空', { icon: 2, offset: '200px' });
                    return;
                }
                
                $.ajax({
                    url: './changePwd.aspx',
                    method:'post',
                    data: { "student_pwd": p1 },
                    success: function (res)
                    {
                        if (res > 0)
                        {
                            layer.alert('修改成功,请重新登录！', { icon: 1, offset: '200px' });
                            setTimeout("window.parent.close();window.open('../index.html', '_blank');", "1000");
                        }
                        else if (res == -1)
                        {
                            layer.alert('和原密码相同', { icon: 2, offset: '200px' });
                        }else
                        {
                            layer.alert('修改失败', { icon: 2, offset: '200px' });
                        }
                    }

                });
            });



        })
    </script>
    
</body>
</html>
